package com.yrw.classdemo;

import java.util.Scanner;

/**
 * @ClassName Homework01
 * @Author 12694
 * @Date 2024/11/1 10:47
 * @Version 1.0
 **/
public class Homework01 {
    public static void main(String[] args) {
        int num;
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入一个正整数：");
        num=scanner.nextInt();
        float sum=test(num);
        System.out.println("sum="+sum);
    }
    public static float test(int num){
        int sign=1;
        float fenmu=1;
        float sum=0;
        if (num<0){
            System.out.println("输入错误！");
            return -1;
        }else if (num==1){
            return 1;
        }else {
            for (int i=2;i<=num;i++){
                sign=-sign;
                fenmu=(fenmu*(2*i-2)*(2*i-1));
                sum=sum+sign/fenmu;
            }
        }
        return sum;
    }
}
